<?php

/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-14 13:05:14
 * @Last Modified by:   Wang chunsheng  email:2192138785@qq.com
 * @Last Modified time: 2020-06-02 23:59:15
 */
use common\addons\diandi_shop\models\enums\GoodsStatus;
use common\helpers\ImageHelper;
use yii2mod\editable\EditableColumn;
use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel common\models\DdGoodsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '商品';
$this->params['breadcrumbs'][] = $this->title;
?>
<?= $this->render('_tab'); ?>

<div class="firetech-main" style="margin-top:20px;">

    <div class="dd-goods-index ">
        <?php echo $this->render('_search', ['model' => $searchModel]); ?>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">商品列表</h3>
            </div>
            <div class="box-body">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    // 'filterModel' => $searchModel,
                    'layout' => "{items}\n{pager}",
                    'columns' => [
                        // ['class' => 'yii\grid\SerialColumn'],
                        'goods_id',
                        'thumb' => [
                            'attribute' => 'thumb',
                            'format' => ['raw'],
                            'value' => function ($model) {
                                $images = $model->thumb;
                                // return $ai_group_status;
                                return Html::img(ImageHelper::tomedia($images), ['width' => 50, 'height' => 50]);
                            },
                        ],
                        'goods_name',
                        'category.name',
                        // 'category_id',
                        // 'spec_type',
                        // 'deduct_stock_type',
                        //'content:ntext',
                        //'sales_initial',
                        'goods_sort',
                        [
                            'class' => EditableColumn::class,
                            'attribute' => 'goods_sort',
                            'value' => function ($model) {
                                return $model->goods_sort;
                            },
                            'url' => ['change-username'],
                            'type' => 'text',
                            // 'editableOptions' => function ($model) {
                            //     return [
                            //         'source' => GoodsStatus::listData(),
                            //         'value' => GoodsStatus::getLabel($model->goods_status),
                            //     ];
                            // },
                        ],

                        //'delivery_id',
                        [
                            'class' => EditableColumn::class,
                            'attribute' => 'goods_status',
                            'value' => function ($model) {
                                return GoodsStatus::getLabel($model->goods_status);
                            },
                            'url' => ['change-username'],
                            'type' => 'select',
                            'editableOptions' => function ($model) {
                                return [
                                    'source' => GoodsStatus::listData(),
                                    'value' => GoodsStatus::getLabel($model->goods_status),
                                ];
                            },
                        ],
                        //'is_delete',
                        //'wxapp_id',
                        //'create_time:datetime',
                        //'update_time:datetime',

                        ['class' => 'common\components\ActionColumn'],
                    ],
                ]); ?>


            </div>
        </div>
    </div>
</div>